package com.numberone.system.util;

import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

/**
 * 通用工具类,主要返回的数据是一个对象里面带状态码,原因,和数据
 * @param <T>
 */
@Setter
@Getter
@NoArgsConstructor
public class JsonResult<T> {
    public static final int CODE_SUCCESS = 200;
    public static final String MSG_SUCCESS = "操作成功";
    public static final int USER_REGISTERED = 201;
    public static final String MSG_REGISTERED = "手机号已经注册";
    public static final int CODE_NOVIP = 202;
    public static final String MSG_NOVIP = "非会员";
    public static final int CODE_NOREFRESH = 203;
    public static final String MSG_NOREFRESH = "没有刷新次数";
    public static final int CODE_NODATA = 204;
    public static final String MSG_NODATA = "没有相应的数据";
    public static final int CODE_NOPUTTASK = 205;
    public static final String MSG_NOPUTTASK = "没有发布次数";
    public static final int CODE_NOBIDLIST = 206;
    public static final String MSG_NOBIDLIST = "昨日无人发布任务";
    public static final int CODE_NOGOODS = 207;
    public static final String MSG_NOGOODS = "查询不到对应商品信息";
    public static final int CODE_NOCARD = 208;
    public static final String MSG_NOCARD = "没有对应卡信息";
    public static final int CODE_PWDERROR = 209;
    public static final String MSG_PWDERROR = "密码错误";
    public static final int CODE_REPEAT = 210;
    public static final String MSG_REPEAT = "重复操作";

    public static final int CODE_NOLOGIN = 401;
    public static final String MSG_NOLOGIN = "请先登录";
    public static final int CODE_ERROR = 500;
    public static final String MSG_ERROR = "系统异常，请联系管理员";



    public static final int CODE_ERROR_PARAM = 501;  //参数异常

    private int code;  //区分不同结果, 而不再是true或者false
    private String msg;
    private T data;  //除了操作结果之后, 还行携带数据返回
    public JsonResult(int code, String msg, T data){
        this.code = code;
        this.msg = msg;
        this.data = data;
    }
    public static <T> JsonResult success(T data){
        return new JsonResult(CODE_SUCCESS, MSG_SUCCESS, data);
    }


    public static JsonResult success(){
        return new JsonResult(CODE_SUCCESS, MSG_SUCCESS, null);
    }

    public static <T> JsonResult error(int code, String msg, T data){
        return new JsonResult(code, msg, data);
    }

    public static JsonResult defaultError(){
        return new JsonResult(CODE_ERROR, MSG_ERROR, null);
    }


    public static JsonResult noLogin() {
        return new JsonResult(CODE_NOLOGIN, MSG_NOLOGIN, null);
    }
    public static JsonResult phoneRegistered() {
        return new JsonResult(USER_REGISTERED, MSG_REGISTERED, null);
    }
    public static JsonResult nodata(){
        return new JsonResult(CODE_NODATA, MSG_NODATA, null);
    }
    public static JsonResult noVip(){
        return new JsonResult(CODE_NOVIP, MSG_NOVIP, null);
    }
    public static JsonResult noRefresh(){
        return new JsonResult(CODE_NOREFRESH, MSG_NOREFRESH, null);
    }
    public static JsonResult noPutTask(){
        return new JsonResult(CODE_NOPUTTASK, MSG_NOPUTTASK, null);
    }
    public static Object NoBidList() {
        return new JsonResult(CODE_NOBIDLIST, MSG_NOBIDLIST, null);
    }
    public static Object noGoods() {
        return new JsonResult(CODE_NOGOODS, MSG_NOGOODS, null);
    }
    public static Object noCard() {
        return new JsonResult(CODE_NOCARD, MSG_NOCARD, null);
    }
    public static Object pwdError() {
        return new JsonResult(CODE_PWDERROR, MSG_PWDERROR, null);
    }
    public static Object repeat() {
        return new JsonResult(CODE_REPEAT, MSG_REPEAT, null);
    }
}
